
import urllib
import urllib.request
import re,os,sys,subprocess
#根据总数来判断

if len(sys.argv)<3:
    print("请输入两个参数，例如：python read_file.py data.txt 2")
    system.exit(0)

data_file_name=sys.argv[1]
thread_num=int(sys.argv[2])

    

data_file=open(data_file_name)

i=0;
total=0
line=data_file.readline()
while line:
    total=total+1
    line=data_file.readline()

one_thread_reqest=(int)(total/thread_num)
if 0!=total%thread_num:
    one_thread_reqest=one_thread_reqest+1
j=0;
while j<thread_num:
    #启动一个线程，把参数传给它
    if j==thread_num-1:
        print(j*one_thread_reqest,total+1)
        #os.system("get.py %d %d"%(j*one_thread_reqest,total+1))
        #os.popen('start '+"get.py %d %d"%(j*one_thread_reqest,total+1)).close()
        p=subprocess.Popen('cmd.exe',shell=False,stdin=subprocess.PIPE)
        cmd="python get.py %s %d %d %d\n"%(data_file_name,j,j*one_thread_reqest,total+1)
        print(cmd)
        p.stdin.write(cmd.encode("utf-8"))
    else:
        print(j*one_thread_reqest,(j+1)*one_thread_reqest)
        #os.system("get.py %s %d %d %d"%(data_file_name,j,j*one_thread_reqest,(j+1)*one_thread_reqest))
        #os.popen('start '+"get.py %s %d %d %d"%(data_file_name,j,j*one_thread_reqest,(j+1)*one_thread_reqest)).close()
        p=subprocess.Popen('cmd.exe',shell=False,stdin=subprocess.PIPE)
        cmd="python get.py %s %d %d %d\n"%(data_file_name,j,j*one_thread_reqest,(j+1)*one_thread_reqest)
        print(cmd)
        p.stdin.write(cmd.encode("utf-8"))
    j=j+1




